// src/category/category.entity.ts
import { Entity, PrimaryGeneratedColumn, Column, OneToMany, CreateDateColumn } from 'typeorm';
import { DesignPage } from '../design/design-page.entity';

@Entity('categories')
export class Category {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ length: 100 })
  name: string;

  @Column({ nullable: true })
  cover_img: string;

  @Column({ type: 'json', nullable: true }) // 新增：图片数组（JSON格式存储）
  images: Record<string, any>; // 或直接使用 `object`

  @Column({ type: 'text', nullable: true })
  description: string;

  @Column({ default: true }) // 新增：控制类别是否显示
  is_visible: boolean;

  @CreateDateColumn()
  createdAt: Date;

  // @OneToMany(() => DesignPage, (page) => page.category)
  @OneToMany(() => DesignPage, (page) => page.category, {
    cascade: true, // 自动保存/删除关联设计页面
    onDelete: 'CASCADE', // 数据库级联删除
  })
  pages: DesignPage[];
}